// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: Implementation of COMCompare.
//   $Id$


#include "stdafx.h"
#include "ComCompare.h"


//Function to compare two COM objects for equality.
//template<class T1,class T2>
//inline bool COMCompare(T1 *p1,T2 *p2)
bool COMCompare(IUnknown* p1,IUnknown* p2)
{
	bool bRet = false;
	if(p1 && p2)
	{
		//Ensure that we are looking at _the_ genuine IUnknown pointers for the objects,
		//	and not just a dodgy cast.
		IUnknown* pUnk1 = 0;
		IUnknown* pUnk2 = 0;
		p1->QueryInterface(IID_IUnknown,(void**)&pUnk1);
		p2->QueryInterface(IID_IUnknown,(void**)&pUnk2);
		
		//Compare the IUnknown pointers received from the QueryInterface calls
		bRet = (pUnk1==pUnk2);
	
		//Release the pointers.
		pUnk1->Release();
		pUnk2->Release();
	}
	else if(!p1 && !p2)
	{
		//if both pointers point to NULL, then they are the same, obviously.
		bRet = true;
	}

	return bRet;

}